package Tree.HuffmanTree;

public class HuffmanTreeNode implements Comparable<HuffmanTreeNode>{
    int weight;
    char data;
    HuffmanTreeNode left;
    HuffmanTreeNode right;

    public HuffmanTreeNode(char data,int weight) {
        this.data = data;
        this.weight = weight;
    }

    public HuffmanTreeNode(char data,int weight, HuffmanTreeNode left, HuffmanTreeNode right) {
        this.weight = weight;
        this.left = left;
        this.right = right;
    }

    @Override
    public int compareTo(HuffmanTreeNode o) {
        return this.weight - o.weight;
    }

    @Override
    public String toString() {
        String dat = data == '\0'?"": String.valueOf(data);
        return "HuffmanTreeNode{data=" + dat + ",weight=" + weight + "}";
    }

    public boolean isLeaf(){
        return left==null&&right==null;
    }
}
